package pow;

/**
 * @author hht
 * @ClassName SOlution
 * @Description TODO
 * @Date 2019/6/5 9:14
 * @VERSION 1.0
 */
public class Solution {
    public static void main(String[] args) {
        long begin = System.currentTimeMillis();
        System.out.println(myPow(2,-2147483648));
        System.out.println(System.currentTimeMillis()-begin);
    }
    public static double myPow(double x, int n) {
        double result = 0;
        if(n==0)
            return  1;
        int flag = 1;
        if(n<0) {
            flag = -1;
            n = n * -1;
        }
        if(n==1) {
            if(flag==-1) {
                result = 1 / x;
            }else{
                result = x;
            }
        }else{
            if(n%2==0){
                double y = myPow(x,n/2);
                result = y*y;
            }else{
                double y = myPow(x,n/2);
                result = y*y*x;
            }
        }
        if(result>Double.MAX_VALUE)
            result = 0;
        return result;
    }
}
